<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <title>传说中的终端页面</title>
    <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
    <link rel="stylesheet" href="/static/css/global.css">

    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap-theme.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">

    <script src="https://cdn.bootcss.com/jquery/3.4.1/core.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js"></script>

    <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
    <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/npm.js"></script>

    <script src="https://cdn.bootcss.com/socket.io/2.3.0/socket.io.js"></script>

    <style>
        .content {
            height: 100vh;
            width: 100vw;
            border: 2px black solid;
            border-radius: 3px;
            margin: 5px;
        }
    </style>
</head>

<body>
    <p class="content">

    </p>

    <script>
        const socket = io();

        socket.on('connect', function () {
            socket.emit('first_connection', {'device name': 'test device for {{username}}',});
            document.title = '【假终端】成功连接服务器';
        });

        socket.on('content upload', function (msg) {
            console.log(msg);
            console.log(JSON.parse(msg));
            $('.content').text(msg);
            document.title = '【假终端】成功更新内容';
        });

        socket.on('disconnect', function () {
            document.title = '【假终端】失去服务器连接！';
        });

        window.onbeforeunload = function () {
            socket.disconnect();
        };
    </script>
</body>

</html>